1. Field of Invention
The field of the invention relates to computer database management systems, computer database application programs, and computer operating systems. In particular, the field of the invention relates to a method and apparatus for performing deferred transactions and undoing prior modifications of data in a database application environment.
2. Related Art
Database management systems are in wide spread use in both stand alone computer systems, such as main frames, as well as in client-server distributed computer systems. Database application programs operate by retrieving data items from these database management systems, performing modifications on these data items, and finally returning the data items to the database management systems. Database management systems are usually accessed through interface functions which control the manner in which data can be accessed, and thereby maintain integrity of the data inside the database management system.
A particular challenge is posed by database application programs which support multi-threaded operation, which can unpredictably affect a data item after is has been retrieved from a database management system. In multi-threaded operation, performance is improved by splitting up the functions of a database application into a set of independently executable tasks. These tasks are then separately executed by a collection of xe2x80x9cthreads.xe2x80x9d This allows the tasks of a database application to be accomplished concurrently, which can greatly increase database application performance. If one thread blocks while performing a particular operation, for example retrieving something from the database management system, another thread can continue to execute another task.
Multi-threading complicates the process of maintaining the integrity of a data item after it has been retrieved from the database management system. In particular, multi-threading complicates the process of moving a data item from a computer""s local memory to the database management system. While one thread is writing the data item to the database, another thread can potentially modify the data item. This can create inconsistencies in the data item if a modification is only partly recorded as the data item is stored to the database management system. Conventional database applications prevent this problem by locking the data item while it is being written to the database management system, so that other threads cannot access it. This locking operation will ensure the data item is stored to the database management system in a consistent state. However, the data item is not accessible by other threads during this commit operation, and system performance can suffer if other threads attempt to access the data items while the commit operation is taking place. This performance delay is particularly noticeable to a human user of the database application program who requests that a data item be stored to the database management system. The human user will typically have to wait until the data item is committed to the database management system before proceeding to operate on the data item.
The performance drawbacks from locking can be overcome in a number of ways. Database application programs can simply eliminate multi-threaded operation, which will eliminate the need to perform any locking. However, doing so will seriously degrade database application performance. Alternatively, the database application user can simply perform fewer commit operations, which will eliminate the delay associated with the commit operations. However, performing fewer commit operations will increase the risk that modifications to data items will be lost during a system failure.
This invention relates to a method and apparatus for performing deferred transactions and undoing modifications to data in a database application program. This method and apparatus allow modifications to a data item to be committed to a database in a background thread while a database application user continues to work on the data item, as if the commit operation had already completed. This is accomplished by placing a read lock on the data item, which allows the data item to be read, but not written to, while the data item is committed to the database by a background thread.
This deferred commit operation has a number of benefits. To a human operator, the deferred commit operation appears to be instantaneous. The human operator can proceed to access the object, and is merely precluded from making subsequent modifications to the object until the commit operation has finished. However, the human user typically takes a significant amount of time to think about and then input subsequent modifications. Consequently, the human user is rarely barred from making further modifications to the object, because it is quite likely that the commit operation will have completed and the read lock will be released before the human user acts to modify the data item.
When a human user initiates a commit operation, if the human user is subsequently barred from performing additional operations until the commit operation is complete. the human user perceives the delay in performing the commit operation to be quite large, even if it is only a few seconds. However, if the human user is allowed to continue working on the data, the human user will require a significant amount of time to think about a new modification and to input this modification. During this lag in human response time, the commit operation is likely to terminate.
The perceived rapid speed of these deferred commit operations makes it more likely that human users will commit data. Data will therefore be committed to permanent storage more frequently, and system failures will consequently have fewer negative consequences.
A preferred embodiment of the deferred commit operation works in a computer system with a local memory which supports concurrent program execution by multiple processes. The computer system is coupled to a database.
The preferred embodiment of the deferred commit operation works as follows. First, a data item is placed in local memory. Either the data item is retrieved from the database and placed in the local memory, or it is produced by the computer system and placed in the local memory. Second, the data item in local memory is modified. Third, a read lock is placed on the data item which allows the computer system""s multiple processes to read the data item, but prevents the multiple processes from writing to write the data item. Fourth, while this read lock is in place, the data item is copied to the database by a background thread, while foreground threads continue to read the data item. Finally, after the copy operation is complete, the read lock is released.
In another preferred embodiment of the deferred commit operation, while the data item is being modified in local memory, a write lock is placed on the data item. This write lock allows only xe2x80x9cuser processes,xe2x80x9d which take commands from a user interface, to access the data item and prevents all other processes from accessing the data item. When the modifications are complete., the write lock is converted to a read lock, which allows the computer system""s multiple processes to read the data item, but prevents the multiple processes from writing to the data item.
A preferred embodiment of the undo feature works as follows. First, a data item is placed in local memory. Second, a copy is made of the data item, and this copy is placed in local memory. Third, modifications are made to the copy. Fourth, if a command is received to undo the modifications, a new copy is created from the original data item. Finally, if a command is received the commit these modifications, a new original data item is created from the modified copy.
Another preferred embodiment of the invention integrates of the above-described deferred commit operation and undo feature into hybrid a system which provides both capabilities.